package com.nbsaas.boot.data.utils;

import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;

public class SqlUtils {


    public static String clearOrderBy(String sql) {
        try {
            Statement statement = CCJSqlParserUtil.parse(sql);
            if (statement instanceof Select) {
                PlainSelect plainSelect = (PlainSelect) statement;
                // 去掉 ORDER BY
                plainSelect.setOrderByElements(null);
                return plainSelect.toString();
            }
        } catch (Exception ignored) {
        }

        return sql;
    }
}
